package com.soft.base.util;

import com.xiaoleilu.hutool.crypto.digest.DigestUtil;
import com.xiaoleilu.hutool.http.HttpUtil;

/**
 * class
 *
 * @author user
 * @date 2020/06/05
 */
public class FileUtil {

    private static String PATH = "/tmp/";

    public static String localizedUrlPath(String url) {
        String extName = com.xiaoleilu.hutool.io.FileUtil.extName(url);
        String localPath = PATH + DigestUtil.md5Hex(url) + "." + extName;
        if (com.xiaoleilu.hutool.io.FileUtil.exist(localPath)) {
            return localPath;
        }
        if (HttpUtil.downloadFile(url, localPath) > 0) {
            return localPath;
        }
        return null;
    }
}
